package com.axis2.spring.init;

import org.apache.axis2.context.ConfigurationContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.engine.ServiceLifeCycle;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created by yc on 2017/4/8.
 */
public class SpringInit implements ServiceLifeCycle {

    @Override
    public void startUp(ConfigurationContext configurationContext, AxisService axisService) {

        try {
            System.out.println("Starting spring init");
            ClassLoader classLoader = axisService.getClassLoader();
            ClassPathXmlApplicationContext appCtx = new
                    ClassPathXmlApplicationContext(new String[] {"applicationContext.xml"}, false);
            appCtx.setClassLoader(classLoader);
            appCtx.refresh();
            System.out.println("spring loaded");
        } catch (Exception ex) {
            ex.printStackTrace();
        }

    }

    @Override
    public void shutDown(ConfigurationContext configurationContext, AxisService axisService) {

    }
}
